package com.xmhmyh.generalframework.common.aliyunOss.controller;

import com.xmhmyh.generalframework.common.aliyunOss.enums.ImgStyle;
import com.xmhmyh.generalframework.common.aliyunOss.service.IAliOssService;
import com.xmhmyh.generalframework.common.aliyunOss.utils.ImgUtils;
import com.xmhmyh.generalframework.common.entity.Response;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.stream.Collectors;

/**
 * @Author: 于丁
 * @DateTime: 2019/12/25 5:01 下午
 */
@Api(tags = "上传图片")
@RestController
@RequestMapping("/sys/ailiUpload")
public class AliOssController {
    @Autowired
    IAliOssService aliOssService;

    @Autowired
    ImgUtils imgUtils;

    @ApiOperation(value = "获取签名")
    @PostMapping("getAliSign")
    public Response getAliSign(String fileType) throws Exception {
        return Response.success(aliOssService.getSign(fileType));
    }

    @ApiOperation(value = "获取图片信息")
    @PostMapping("getImgPath")
    public Response getImgPath(String path) {
        return Response.success(imgUtils.genImgPath(path, ImgStyle.BIG.getLabel()));
    }
    @ApiOperation(value = "获取文件地址")
    @PostMapping("getFilePath")
    public Response getFilePath(String path) {
        return Response.success(imgUtils.genFilePath(path));
    }

    @ApiOperation(value = "批量获取")
    @PostMapping("getImgPathList")
    public Response getImgPath(@RequestBody List<String> path) {
        List<String> imgPathList = path.stream().map(img -> {
            return imgUtils.genImgPath(img, ImgStyle.BIG.getLabel());
        }).collect(Collectors.toList());
        return Response.success(imgPathList);
    }

}
